<template>
  <el-card class="app-container">
    <c-u-r-d-table :option="option" ref="table"/>
    <el-dialog :visible.sync="spotDialogShowed" title="商品管理" width="1000px">
      <shop-goods-list ref="shopGoodsTable" :shop-id="shopId"/>
    </el-dialog>
  </el-card>
</template>

<script>

import ColumnType from '@/framework/constant/ColumnType'
import {shopApi} from '@/feature/lms/infra/api/shopApi'
import CURDTable from '@/framework/components/table/CURDTable'
import {scenicSpotTagApi} from "@/feature/mj/infra/api/scenicSpotTagApi";
import {tagApi} from "@/feature/lms/infra/api/tagApi";
import ShopGoodsList from "@/feature/lms/app/shop-goods";
import {shopCategoryApi} from "@/feature/lms/infra/api/shopCategoryApi";

export default {
  components: {ShopGoodsList, CURDTable},
  data: function () {
    return {
      spotDialogShowed: false,
      shopId: 0,
      option: {
        requestApi: shopApi,
        loadDetail: true,
        showSelection: false,
        columns: [
          {
            label: '封面',
            prop: 'cover',
            width: 80,
            required: true,
            type: ColumnType.IMAGE
          },
          {
            label: '商家名称',
            required: true,
            width: 120,
            prop: 'shopName',
            searchable: true
          }, {
            label: '商家分类',
            required: true,
            width: 50,
            prop: 'categoryId',
            searchable: true,
            type: ColumnType.SELECT,
            options: shopCategoryApi.listAll()
          },
          {
            label: '人均价格',
            prop: 'price',
            required: false,
            width: 80,
            type: ColumnType.NUMBER,
            searchable: true,
            renderOptions: {
              min: 0
            }
          },
          {
            label: '商家电话',
            width: 110,
            prop: 'telephone',
            searchable: true
          },
          {
            label: '标签',
            required: false,
            span: 24,
            hiddenInTable: true,
            type: ColumnType.MUL_SELECT,
            prop: 'tagIdList',
            dataType: 'array',
            options: tagApi.listAll()
          },
          {
            label: '按钮内容',
            hiddenInTable: true,
            required: false,
            width: 120,
            prop: 'buttonText',
            type: ColumnType.TEXT
          }, {
            label: '按钮链接',
            viewAsLink: true,
            hiddenInTable: false,
            required: false,
            width: 140,
            prop: 'buttonLink',
            type: ColumnType.LINK
          },
          {
            label: '图片',
            span: 24,
            hiddenInTable: true,
            required: true,
            type: ColumnType.IMAGE,
            limit: 10,
            prop: 'photoList',
            dataType: 'array'
          },
          {
            label: '排序号',
            span: 24,
            required: true,
            width: 80,
            defaultValue: 0,
            prop: 'sortNum',
            type: ColumnType.NUMBER
          },
          {
            label: '折扣',
            type: ColumnType.NUMBER,
            hiddenInTable: true,
            required: false,
            renderOptions: {
              min: 0,
              max: 9
            },
            width: 80,
            prop: 'discount'
          },
          {
            label: '地址名称',
            prop: 'addressName',
            required: true,
            width: 'auto',
            type: ColumnType.TEXT
          },
          {
            label: '简介',
            width: 'auto',
            required: true,
            hiddenInTable: true,
            type: ColumnType.TEXTAREA,
            prop: 'brief',
            span: 24
          },
          {
            label: '创建时间',
            type: ColumnType.DATETIME,
            hiddenInForm: true,
            prop: 'gmtCreate'
          },
          {
            label: '修改时间',
            type: ColumnType.DATETIME,
            hiddenInForm: true,
            prop: 'gmtModified'
          }
        ]
      }
    }
  },
  methods: {
    handleGoodsManager({arg: row}) {
      this.shopId = row.id
      this.spotDialogShowed = true
      this.$nextTick(() => {
        this.$refs.shopGoodsTable.refresh()
      })
    }
  }
}
</script>

